package cn.mesmile.es.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.DateSerializer;
import com.fasterxml.jackson.databind.ser.std.StringSerializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Date;

/**
 * @author zb
 * @date 2021/6/6 12:36
 * @Description:
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@Document(indexName = "book", type = "book")
public class Book implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     *  text 分词，其他类型 不分词
     *  keyword 不分词
     */
    @Id
    private Long id;

    @Field(type= FieldType.Keyword)
    private String name;

    @Field(type= FieldType.Integer)
    private Integer pageSize;

    @Field(type= FieldType.Date)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date publishDate;

    /**
     * 建立索引的 分词器 和 搜索的分词器 应该保持一致; text 应该指定分词器
     */
    @Field(type= FieldType.Text, analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
    private String description;

    @Field(type= FieldType.Boolean)
    private Boolean isPublic;

    /**
     *  Nested 告诉ES当前是一个对象 ，作为json
     */
    @Field(type= FieldType.Nested)
    private Author author;

}
